// function twoSum(nums, target) {
//   const numArr = new Set()
//   let firNum = 0
//   let total = target
//   while (firNum !== nums.length - 1 && total <= target) {
//     nums.forEach((element, index) => {
//       let totalNum = nums[firNum] + element
//       if (index > firNum && totalNum <= target) {
//         if (totalNum === target) {
//           numArr.add(firNum)
//           numArr.add(index)
//         }
//         total = totalNum
//       }
//     })
//     firNum++
//   }
//   return Array.from(numArr)
// }
function twoSum(nums, target) {
  const targetArr = {}
  let res = []
  nums.forEach((element, index) => {
    let num = target - element
    if (num in targetArr) {
      res.push(targetArr[num], index)
    }
    targetArr[element] = index
  })
  return res
}
console.log(twoSum([3, 3], 6))
